<?php
namespace Mob\Model;
use Think\Model\RelationModel;
class UserRegbusinessModel extends  RelationModel 
{
	protected $_link = array(
                'RegisterBusiness'=>array(
                    'mapping_type'=> self::BELONGS_TO,
                    'mapping_name'=> 'business',
                    'class_name'=> 'RegisterBusiness',
                    'foreign_key'=>'businesid'
                ),
    );
    
    
    protected $_validate = array(
        array('uid','require','用户ID不能为空！'), 
        array('businesid','require','平台域名注册商不能为空！'), 
        array('busicode','require','用户在此域名注册商平台上的账号不能为空！'),
       // array('busicode','','此域名注册商平台上账号已注册,请核实！',0,'unique',1), 
    );
    
    /**
     * 插入用户注册商
     * @param unknown $arry
     * @return number|unknown
     */
    public function inst($arry)
    {
        $UserReg = D("user_regbusiness");
        foreach ($arry as $key => $value){
            $data[$key] = $value;
        };
        $result["status"]=0;
        if (!$UserReg->create($data)){
            $result["mess"]=$UserReg->getError();
        }else{
            $result = $UserReg->add(); // 写入数据到数据库
            if($result){
                $result["status"]=1;
                $result["mess"]=$result;
            }
        };
        return $result;
    }
    
    /**
     * 查询用户注册商
     * @param unknown $arry
     * @return mixed|boolean|string|NULL|unknown|object
     */
	public function getList($arry)
	{
		foreach ($arry as $key => $value){
	        $condition[$key] = $value;
	    };
        return $this->relation(true)->where($condition)->order('id desc')->select();
	}
	
	/**
	 * 查询用户注册商数量
	 * @param unknown $arry
	 * @return mixed|boolean|string|NULL|unknown|object
	 */
	public function getCount($arry)
	{
	    foreach ($arry as $key => $value){
	        $condition[$key] = $value;
	    };
	    return $this->where($condition)->count();
	}
}
?>